/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.panomedic.gui;

import java.awt.BorderLayout;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Rectangle;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JProgressBar;

/**
 *
 * @author Yare
 */
public class ProgressDialog extends JDialog {

    JPanel contentPane = new JPanel(new BorderLayout());
    private JProgressBar progress;
    private int max = 0;

    public ProgressDialog(Frame owner, int max) {
        super(owner, new String("Processing...."), false);
        this.max = max;

        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));


        progress = new JProgressBar(0, max);
        progress.setValue(0);
        progress.setStringPainted(true);

        contentPane.add(progress, BorderLayout.CENTER);


        contentPane.setOpaque(true);
        this.setContentPane(contentPane);

        setResizable(false);
//        this.setLocation(300, 300);
        this.setSize(new Dimension(200, 100));
//        this.setLocationRelativeTo(owner);
        this.setVisible(true);
    }

    public void setProgress(int value) {
        if (value == max) {
            setCursor(null);
            this.setVisible(false);
        } else {
            progress.setValue(value);
            Rectangle progressRect = progress.getBounds();
            progressRect.x = 0;
            progressRect.y = 0;
            progress.paintImmediately(progressRect);
        }
    }
}
